use proc_macro::TokenStream;
use syn::parse_macro_input;

macro_rules! convert_expand_result {
    ($e:expr) => {
        match $e {
            Ok(val) => val.into(),
            Err(err) => err.into_compile_error().into(),
        }
    };
}

#[proc_macro_derive(Validator, attributes(validate, name))]
pub fn derive_from_meta(input: TokenStream) -> TokenStream {
    let expand_result = validator_expand::validator_derive::expand(&parse_macro_input!(input));
    convert_expand_result!(expand_result)
}
